package com.sprucetec.live.service.impl;

import com.sprucetec.live.common.webcontext.LoginUserContext;
import com.sprucetec.live.entity.LiveVideoHlsDetail;
import com.sprucetec.live.entity.LiveVideoServerDetail;
import com.sprucetec.live.enums.DeleteStatusEnum;
import com.sprucetec.live.mapper.LiveVideoHlsDetailMapper;
import com.sprucetec.live.service.LiveVideoHlsDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

/**
 * @author chenkai
 * @date 2020/4/1 11:02 上午
 * @description:
 */
@Slf4j
@Service("liveVideoHlsDetailService")
public class LiveVideoHlsDetailServiceImpl implements LiveVideoHlsDetailService {

    @Autowired
    private LiveVideoHlsDetailMapper liveVideoHlsDetailMapper;

    @Override
    public void batchInsert(List<LiveVideoHlsDetail> list) {
        liveVideoHlsDetailMapper.batchInsert(list);
    }

    @Override
    public void deleteHlsDetail(Long liveVideoId) {
        Example example = new Example(LiveVideoServerDetail.class);
        example.createCriteria().andEqualTo("liveVideoId", liveVideoId);

        LiveVideoHlsDetail videoHlsDetail = new LiveVideoHlsDetail();
        videoHlsDetail.setIsDeleted(DeleteStatusEnum.DELETED.getCode());
        videoHlsDetail.setUpdateTime(new Date());
        videoHlsDetail.setUpdateUserCode(LoginUserContext.getUser().getUid());
        videoHlsDetail.setUpdateUserName(LoginUserContext.getUser().getName());
        liveVideoHlsDetailMapper.updateByExampleSelective(videoHlsDetail, example);
    }

    @Override
    public List<LiveVideoHlsDetail> getHlsDetailList(Long liveVideoId) {
        Example example = new Example(LiveVideoServerDetail.class);
        example.createCriteria().andEqualTo("liveVideoId", liveVideoId).andEqualTo("isDeleted", DeleteStatusEnum.VALID.getCode());
        return liveVideoHlsDetailMapper.selectByExample(example);
    }
}
